var menuHandler = {
	persistmenu : "yes",
	persisttype : "sitewide",

	SwitchMenu : function(obj) {
        if (document.getElementById) {
            var el = document.getElementById(obj);
            var ar = document.getElementById("masterdiv").getElementsByTagName("span");
            if (el.style.display != "block") {
                for (var i = 0; i < ar.length; i++) {
                    if (ar[i].className == "submenu")
                        ar[i].style.display = "none";
                }
                el.style.display = "block";
            } else {
                el.style.display = "none";
            }
        }
    },

	get_cookie : function(Name) {
        var search = Name + "=";
        var returnvalue = "";
        if (document.cookie.length > 0) {
            offset = document.cookie.indexOf(search);
            if (offset != -1) {
                offset += search.length;
                end = document.cookie.indexOf(";", offset);
                if (end == -1) end = document.cookie.length;
                returnvalue = unescape(document.cookie.substring(offset, end));
            }
        }
        return returnvalue;
    },

	onloadfunction : function() {
		if (document.getElementById('menu1'))
			document.getElementById('menu1').onclick = function() { menuHandler.SwitchMenu('sub1'); };
		if (document.getElementById('menu2'))
			document.getElementById('menu2').onclick = function() { menuHandler.SwitchMenu('sub2'); };
		
		
        if (this.persistmenu == "yes") {
            var cookiename = (this.persisttype == "sitewide") ? "switchmenu" : window.location.pathname;
            var cookievalue = menuHandler.get_cookie(cookiename);
            if (cookievalue != "")
                document.getElementById(cookievalue).style.display = "block";
        }
    },

	savemenustate : function() {
        var inc = 1, blockid = "";
        while (document.getElementById("sub" + inc)) {
            if (document.getElementById("sub" + inc).style.display == "block") {
                blockid = "sub" + inc;
                break;
            }
            inc++;
        }
        var cookiename = (this.persisttype == "sitewide") ? "switchmenu" : window.location.pathname;
        var cookievalue = (this.persisttype == "sitewide") ? blockid + ";path=/" : blockid;
        document.cookie = cookiename + "=" + cookievalue;
    }
}